import Vue from 'vue'
import Router from 'vue-router'
import Login from '../components/login.vue'
import home from '../components/Home.vue'
// 不知道为什么引入不了字体文件夹
// import './src/assets/fonts/iconfont.css'
import Welcome from '../components/Welcome.vue'
import Users from '../components/user/users.vue'
import rights from '../components/power/rights.vue'
import Roles from '../components/power/Roles.vue'
import Cate from '../components/goods/cate.vue'

import {
  Form
} from '../node_modules/element-ui';

// axios.interceptors.request.use(config=>{
//   config.headers.Authorization =window.sessionStorage.getItem('token');
//   return config;
// });


Vue.use(Router)

const router = new Router({
  routes: [{
      path: '/',
      redirect: '/login'
    },
    {
      path: '/login',
      component: Login
    },
    {
      path: '/home',
      component: home,
      redirect: '/welcome',
      children:[{path:'/welcome',component:Welcome},
                {path:'/users',component:Users},
                {path:'/rights',component:rights},
              {path:'/roles',component:Roles},
                {path:'/categories',component:Cate}]
    }
  ]
})

router.beforeEach((to, from, next) => {

  if (to.path === '/login') return next();

  // 获取tonken
  var tonken = window.sessionStorage.getItem('token');

  if (!tonken) return next();
  next();
})

export default router
